<?php
// +---------------------------------------------------------------------+
// | OneBase    | [ WE CAN DO IT JUST THINK ]                            |
// +---------------------------------------------------------------------+
// | Licensed   | http://www.apache.org/licenses/LICENSE-2.0 )           |
// +---------------------------------------------------------------------+
// | Author     | Bigotry <3162875@qq.com>                               |
// +---------------------------------------------------------------------+
// | Repository | https://gitee.com/Bigotry/OneBase                      |
// +---------------------------------------------------------------------+

namespace app\admin\controller;

use app\common\model\CountryMobileArea;
use app\common\model\UserLevel;

/**
 * 会员控制器
 */
class Member extends AdminBase
{

    /**
     * 会员授权
     */
    public function memberAuth()
    {
        
        IS_POST && $this->jump($this->logicMember->addToGroup($this->param));
        
        // 所有的权限组
        $group_list = $this->logicAuthGroup->getAuthGroupList(['member_id' => MEMBER_ID]);
        
        // 会员当前权限组
        $member_group_list = $this->logicAuthGroupAccess->getMemberGroupInfo($this->param['id']);

        // 选择权限组
        $list = $this->logicAuthGroup->selectAuthGroupList($group_list, $member_group_list);
        
        $this->assign('list', $list);
        
        $this->assign('id', $this->param['id']);
        
        return $this->fetch('member_auth');
    }
    
    /**
     * 会员列表
     */
    public function memberList()
    {

        if(!empty($this->param['reg_ip']) || !empty($this->param['uuid']) ){
            $this->assign('list', $this->logicMember->getMemberList($this->param,'a.*','a.create_time desc,a.id desc',50));

            return $this->fetch('member_list_ip');
        }
        $this->assign('list', $this->logicMember->getMemberList($this->param,'a.*','a.create_time desc,a.id desc',50));
        $this->assign('level', UserLevel::all());
        $this->assign('param',$this->param);
        return $this->fetch('member_list');
    }

    /**
     * 会员币币账户
     */
    public function memberExchangeCoin()
    {

        $this->param['type']=2;
        $this->assign('list', $this->logicMember->getMemberList($this->param,'a.*','a.create_time desc,a.id desc',50));
        return $this->fetch('exchange_coin_list');
    }


    /**
     * 亏损会员
     */
    public function lose_member()
    {

        $this->param['is_lose']=2;
        $this->assign('list', $this->logicMember->getMemberList($this->param,'a.*','a.create_time desc,a.id desc',50));
        $this->assign('param',$this->param);
        $this->assign('release',getConfig('user_lose_money_release'));
        return $this->fetch('lose_member_list');
    }


    /**
     * 会员登陆记录
     */
    public function login_log()
    {


        $this->assign('list', $this->logicMember->getloginlogList($this->param,'a.*,c.username,c.mobile','a.create_time desc,a.id desc',50));
        return $this->fetch('login_log');
    }

    /**
     * 会员登陆记录
     */
    public function lose_release_log()
    {


        $this->assign('list', $this->logicMember->lose_release_log($this->param,'a.*,c.username,c.mobile','a.create_time desc,a.id desc',50));
        return $this->fetch();
    }

    /**
     * 会员权限
     */
    public function member_auth_list()
    {


        $this->assign('list', $this->logicMember->getMemberList($this->param,'a.*','a.create_time desc,a.id desc',50));
        return $this->fetch('member_auth_list');
    }
    /**
     * 不良记录
     */
    public function bad_record()
    {


        $this->assign('list', $this->logicMember->bad_record($this->param,'a.*,c.username','a.create_time desc,a.id desc',50));
        return $this->fetch('user_bad_record');
    }



    /**
     * 会员反馈列表
     */
    public function member_feedback()
    {


        $this->assign('list', $this->logicMember->member_feedback($this->param,'a.*,c.username,c.mobile','a.create_time desc',50));

        return $this->fetch();
    }

    /**
     * 会员导出
     */
    public function exportMemberList()
    {
        
       // $where = $this->logicMember->getWhere($this->param);
        
        $this->logicMember->exportMemberList($this->param);
    }
    
    /**
     * 会员添加
     */
    public function memberAdd()
    {
        
        IS_POST && $this->jump($this->logicMember->memberAdd($this->param));
        $this->assign('area', CountryMobileArea::where(['status'=>1])->order('sort desc')->select());
        return $this->fetch('member_add');
    }
    
    /**
     * 会员编辑
     */
    public function memberEdit()
    {
        
        IS_POST && $this->jump($this->logicMember->memberEdit($this->param));
        
        $info = $this->logicMember->getMemberInfo(['id' => $this->param['id']]);
        $this->assign('level', UserLevel::all());
        $this->assign('info', $info);
        
        return $this->fetch('member_edit');
    }
    
    /**
     * 会员删除
     */
    public function memberDel($id = 0)
    {
        
        return $this->jump($this->logicMember->memberDel(['id' => $id]));
    }
    
    /**
     * 修改密码
     */
    public function editPassword()
    {
        
        IS_POST && $this->jump($this->logicMember->editPassword($this->param));
        
        $info = $this->logicMember->getMemberInfo(['id' => MEMBER_ID]);
        
        $this->assign('info', $info);
        
        return $this->fetch('edit_password');
    }

    /**
     * 数据状态设置
     */
    public function update_info()
    {

        $this->jump($this->logicMember->update_info( $this->param));
    }

    /**
     * 会员列表
     */
    public function member_level()
    {


        IS_AJAX && IS_POST &&  $this->jump($this->logicMember->member_level($this->param));
        empty($this->param['id']) && $this->param['id']=2;
        $this->assign('id', $this->param['id']);
        return $this->fetch();
    }


   /**
    *同注册IP检测
    */
   public function ip_check_list(){
       $this->assign('list', $this->logicMember->getIpMemberList('reg_ip'));
       $this->param['type']=1;
       $this->assign('param', $this->param);
       return $this->fetch('ip_check_list');
   }


    /**
     *同设备号检测
     */
    public function uuid_check_list(){
        $this->param['type']=2;
        $this->assign('param', $this->param);
        $this->assign('list', $this->logicMember->getIpMemberList('uuid'));
        return $this->fetch('ip_check_list');

    }


    /**
     *在线会员
     */
    public function online_member(){
        $this->assign('list', $this->logicMember->getSameMemberList($this->param));
        $this->assign('param', $this->param);
        return $this->fetch('member_list_online');
    }

    /***
     * 会员链上记账统计
     */
    public function  user_chain_log(){
        $this->assign('list', $this->logicMember->getMemberList($this->param,'a.*','a.create_time desc,a.id desc',50));
        $this->assign('param', $this->param);
        return $this->fetch('user_chain_log');
    }

    /***
     * 会员链上记账更多
     */
    public function  game_log(){
        $this->assign('list', $this->logicMember->getGameLogList($this->param,'a.*,c.username','a.create_time desc,a.id desc',50));
        $this->assign('param', $this->param);
        return $this->fetch('game_log');
    }



    /***
     * 会员链上记账明细
     */
    public function  chain_statistics(){
        $this->assign('list', $this->logicMember->getChainLogList($this->param,'a.*','a.create_time desc,a.id desc',50));
        $this->assign('param', $this->param);
        return $this->fetch('chain_statistics');
    }

    /***
     * 系统地址记账添加
     */
    public function  chain_statistics_add(){

        IS_POST && $this->jump($this->logicMember->chain_statistics_add($this->param));
        return $this->fetch('chain_statistics_add');
    }


}
